package org.example.text;

public class Bank {
    // 开户
    public Account openAccount(long id, String pwd,int type){// 多态应用在方法的返回值
        Account account = null;
        switch (type){
            case 0:{
                account = new Account(id,0,pwd);
                break;
            }
            case 1:{
                account = new SavingAccount(id,0,pwd);
                break;
            }
            case 2:{
                account = new CreditAccount(id,0,pwd,10000);
                break;
            }
        }
        return account;
    }
    // 存款
    public double deposit(Account a,double amount){
        // 获取账户余额
        double balance = a.getBalance();
        // 计算
        balance += amount;
        // 更新余额
        a.setBalance(balance);
        return balance;
    }
    // 取款
    public double withdraw(Account a,double amount){
        // 获取余额
        double balance = a.getBalance();
        // 计算
        balance -= amount;
        // 更新余额
        a.setBalance(balance);
        return balance;
    }
}
